package com.zkingsoft.services.sys.impl;

import com.zkingsoft.dao.sys.SysBtnDao;
import org.springframework.beans.factory.annotation.Autowired;
import com.zkingsoft.util.ModelUtils;
import com.zkingsoft.pojo.PaginationVO;
import java.util.List;
import com.zkingsoft.services.sys.SysBtnService;
import com.zkingsoft.sqlUtil.ServiceUtil;

import org.springframework.stereotype.Service;
import com.zkingsoft.exception.GlobleException;
import java.util.Map;
import com.zkingsoft.model.sys.SysBtn;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2016-11-17 16:43
 */
@Service("sysBtnService")
public class SysBtnServiceImpl implements SysBtnService {

	@Autowired
	private SysBtnDao sysBtnDao;

	@Autowired
	private ServiceUtil serviceUtil;

	private final String tableName = "sys_btn";

	@Override
	public int add(SysBtn sysBtn) {

		if (serviceUtil.addCheckRepeat(tableName, "btn_value", sysBtn.getBtnValue())) {
			throw new GlobleException("value值已经存在");
		}
		return sysBtnDao.insert(sysBtn);

	}

	@Override
	public int batchAdd(List<SysBtn> sysBtnList) {
		return sysBtnDao.batchInsert(sysBtnList);
	}

	@Override
	public int modifyByMap(SysBtn oldSysBtn, SysBtn newSysBtn) {

		if (serviceUtil.updateCheckRepeat(tableName, "btn_value", newSysBtn.getBtnValue(), "btn_id",
				newSysBtn.getBtnId())) {
			throw new GlobleException("value值已经存在");
		}

		if (!ModelUtils.isModified(oldSysBtn, newSysBtn)) {
			return 1;
		}
		Map<String, Object> modifyMap = null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldSysBtn, newSysBtn);
		} catch (Exception e) {
			throw 	new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("btnId", oldSysBtn.getBtnId());
			sysBtnDao.updateByMap(modifyMap);
		}
		return 1;
	}

	@Override
	public int modifyByModel(SysBtn sysBtn) {

		return sysBtnDao.updateByModel(sysBtn);

	}

	@Override
	public int remove(List<Long> list) {

		return sysBtnDao.deleteByIds(list);

	}

	@Override
	public int removeById(Long btnId) {

		return sysBtnDao.deleteById(btnId);

	}

	@Override
	public int removeByModel(SysBtn sysBtn) {

		return sysBtnDao.deleteByModel(sysBtn);

	}

	@Override
	public List<SysBtn> findInPage(SysBtn sysBtn, PaginationVO pageVo) {

		return sysBtnDao.selectInPage(sysBtn, pageVo);

	}

	@Override
	public List<SysBtn> findByModel(SysBtn sysBtn) {

		return sysBtnDao.selectByModel(sysBtn);

	}

	@Override
	public int findTotal(SysBtn sysBtn) {

		return sysBtnDao.selectTotalRecord(sysBtn);

	}

	@Override
	public SysBtn findById(Long btnId) {

		return sysBtnDao.selectById(btnId);

	}

}